package cn.cvs.controller;

import cn.cvs.pojo.SysUser;
import cn.cvs.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
public class LoginController {

    @Resource
    UserService userService;
    //@ResponseBody
    @RequestMapping("/test")
    public String test(){
        return "index.jsp";
    }


   // @RequestMapping(value = {"/","/login","/toLogin","/login.jsp"})
    public String toLogin(Map<String,Object> map){
        map.put("name","hello jsp");
        return "login.jsp";
    }
   // @RequestMapping(value = {"/doLogin"})
    public String doLogin(@RequestParam("username") String username
                        , @RequestParam("password") String password
                        , HttpServletRequest request
                          ){
        SysUser loginUser = userService.doLogin(username, password);
        if (null != loginUser){
            request.getSession().setAttribute("currUser",loginUser);
            return "index.jsp";
        }else{
            return "login.jsp";
        }
    }
}
